home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
sound
/
fftscop4.zip
/
BATCH.C
next >
Wrap
C/C++ Source or Header
|
1994-06-29
|
37KB
|
1,590 lines
#include <dos.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
#include <string.h>
#include <mem.h>
#include <math.h>
#define TWO_PI ((double)2.0 * M_PI)
typedef unsigned char DacPalette256[256][3];
typedef struct tagBITMAPFILEHEADER
{
unsigned int bfType; // "BM" or 0x4D42
unsigned long bfSize; // Size of file in bytes
unsigned int bfReserved1; // Set to 0
unsigned int bfReserved2; // Set to 0
unsigned long bfOffBits; // Offset in file where
// the bits begin
} BITMAPFILEHEADER;
typedef struct tagBITMAPINFOHEADER
{
unsigned long biSize; // Size of the structure
unsigned long biWidth; // Width in pixels
unsigned long biHeight; // Height in pixels
unsigned int biPlanes; // # of color Planes: Set to 1
unsigned int biBitCount; // Color bits per pixel
unsigned long biCompression; // Compression Scheme
unsigned long biSizeImage; // Number of bitmap bytes
unsigned long biXPelsPerMeter; // Horizontal Resolution
unsigned long biYPelsPerMeter; // Vertical Resolution
unsigned long biClrUsed; // Number of colors used
unsigned long biClrImportant; // Important colors
} BITMAPINFOHEADER;
char bildname[70];
unsigned char far *VGAmem;
struct text_info tiGFX;
struct REGPACK regp;
union REGS reg;
int Linecolor=1,WritePage=0,HighSpeed=0,Triggerbuffer=999;
int minX=0,minY=0,maxx=320,maxy=200;
BITMAPFILEHEADER BMPHeader;
BITMAPINFOHEADER BMPInfo;
double stauch=1; //Bilschirmstauchfaktor
int Xadd=0,Yadd=0; //Position der linken Oberen Ecke der BMP
long BytesDiff,BytesTMP;
DacPalette256 Hallo;
/* Globals */
int samples, power;
double real[2048], imag[2048], max, Pegel=10,FFTmax;
FILE *fpi, *fpo;
/* Prototypes and forward declarations */
void fft(void), max_amp(void);
int permute(int);
double magnitude(int);
void dspwrite ( unsigned char );
unsigned char dspread ( void );
unsigned Buffer[2048];
unsigned SBuffer[8900];
unsigned char far *data;
unsigned char far *aligned;
unsigned char far aligned_physical;
/* Getvgapalette256 gets the entire 256 color palette */
/* PalBuf contains RGB values for all 256 colors */
/* R,G,B values range from 0 to 63 */
/* Usage: */
/* DacPalette256 dac256; */
/* */
/* getvgapalette256(&dac256); */
void getvgapalette256(DacPalette256 *PalBuf)
{
regp.r_ax = 0x1017;
regp.r_bx = 0;
regp.r_cx = 256;
regp.r_es = FP_SEG(PalBuf);
regp.r_dx = FP_OFF(PalBuf);
intr(0x10,®p);
}
/* Setvgapalette256 sets the entire 256 color palette */
/* PalBuf contains RGB values for all 256 colors */
/* R,G,B values range from 0 to 63 */
/* Usage: */
/* DacPalette256 dac256; */
/* */
/* setvgapalette256(&dac256); */
void setvgapalette256(DacPalette256 *PalBuf)
{
regp.r_ax = 0x1012;
regp.r_bx = 0;
regp.r_cx = 256;
regp.r_es = FP_SEG(PalBuf);
regp.r_dx = FP_OFF(PalBuf);
intr(0x10,®p);
}
void Grafik(int GFXmode) // 13, 14, 17mono, 18, 19vga, -1,3
{ //320x200, 640x200, 640x480, 640x480, 320x200, text
VGAmem=(char far *)MK_FP(0xa000,0);
if (GFXmode>=0)
{
gettextinfo(&tiGFX);
regp.r_ax = GFXmode;
intr(0x10,®p);
}
if (GFXmode<0)
{
regp.r_ax = tiGFX.currmode;
intr(0x10,®p);
}
}
void Putpixel(int x, int y)
{
reg.h.ah = 0x0c;
reg.h.al = Linecolor;
reg.h.bh = WritePage;
reg.x.cx = x;
reg.x.dx = y;
int86(0x10,®,®);
}
void Putpixel2(int x, int y)
{
reg.h.ah = 0x0c;
reg.h.al = 0;
reg.h.bh = WritePage;
reg.x.cx = x;
reg.x.dx = y;
int86(0x10,®,®);
}
void Putpixel3(int x, int y)
{
reg.h.ah = 0x0c;
reg.h.al = 235-y;
reg.h.bh = WritePage;
reg.x.cx = x;
reg.x.dx = y;
int86(0x10,®,®);
}
int Getpixel(int x, int y)
{
if(x<minX)return 0;
if(y<minY)return 0;
if(x>=maxx)return 0;
if(y>=maxy)return 0;
reg.h.ah = 0x0d;
reg.h.bh = WritePage;
reg.x.cx = x;
reg.x.dx = y;
int86(0x10,®,®);
return reg.h.al;
}
void singlecolor256(int nr,int r,int g,int b)
{
reg.h.ah = 0x10;
reg.h.al = 0x10;
reg.x.bx = nr;
reg.h.ch = g;
reg.h.cl = b;
reg.h.dh = r;
int86(0x10,®,®);
}
void singlecolor16(int nr,int r,int g,int b)
{
reg.h.ah=0x10;
reg.h.al=0x07;
reg.h.bl=nr;
int86(0x10,®,®);
nr=reg.h.bh;
reg.h.ah = 0x10;
reg.h.al = 0x10;
reg.x.bx = nr;
reg.h.ch = g;
reg.h.cl = b;
reg.h.dh = r;
int86(0x10,®,®);
}
void setzePunkt(int Xposi,int Yposi,int Farben)
{
int xx=Xadd+(Xposi/stauch),yy=Yadd+(Yposi/stauch);
if((xx<0)||(yy<0)||(xx>=320)||(yy>=200))return;
*(VGAmem+xx+320*yy)=Farben;
}
void leseBMP1(char *BMPFile) //1Bit BMP-Datei
{
int filepos=0,fx=0,fy=0,farbe;
FILE *Fn;
Fn=fopen(BMPFile,"rb"); //überlese File-Header
for(filepos=0;filepos<(BMPHeader.bfOffBits);filepos++)farbe=getc(Fn);
for(farbe=0;farbe<8;farbe++)Buffer[farbe]= 63*(farbe &4);
for(farbe=0;farbe<16;farbe++)
{ //codiere Farbpalette:
Hallo[farbe][2]=Buffer[4*farbe+0]/4;
Hallo[farbe][1]=Buffer[4*farbe+1]/4;
Hallo[farbe][0]=Buffer[4*farbe+2]/4;
}
setvgapalette256(&Hallo); //aktiviere Palette "Hallo"
BytesDiff=BMPInfo.biWidth%32;
if (BytesDiff>0)BytesDiff=4-BytesDiff/8-((BytesDiff%8>0)?1:0);
for(fy=0;fy<BMPInfo.biHeight;fy++) //lese Bitmap...
{
for(fx=0;fx<BMPInfo.biWidth;) //benutzt Farbe 0/1
{
farbe=getc(Fn);
setzePunkt(fx++,((BMPInfo.biHeight-1)-fy),(farbe&128)/128);
if(fx>=BMPInfo.biWidth)break;
farbe<<=1;
setzePunkt(fx++,((BMPInfo.biHeight-1)-fy),(farbe&128)/128);
if(fx>=BMPInfo.biWidth)break;
farbe<<=1;
setzePunkt(fx++,((BMPInfo.biHeight-1)-fy),(farbe&128)/128);
if(fx>=BMPInfo.biWidth)break;
farbe<<=1;
setzePunkt(fx++,((BMPInfo.biHeight-1)-fy),(farbe&128)/128);
if(fx>=BMPInfo.biWidth)break;
farbe<<=1;
setzePunkt(fx++,((BMPInfo.biHeight-1)-fy),(farbe&128)/128);
if(fx>=BMPInfo.biWidth)break;
farbe<<=1;
setzePunkt(fx++,((BMPInfo.biHeight-1)-fy),(farbe&128)/128);
if(fx>=BMPInfo.biWidth)break;
farbe<<=1;
setzePunkt(fx++,((BMPInfo.biHeight-1)-fy),(farbe&128)/128);
if(fx>=BMPInfo.biWidth)break;
farbe<<=1;
setzePunkt(fx++,((BMPInfo.biHeight-1)-fy),(farbe&128)/128);
}
BytesTMP=BytesDiff;
while(BytesTMP--)farbe=getc(Fn);
}
fclose(Fn);
}
void leseBMP4(char *BMPFile) //4Bit BMP-Datei
{
int filepos=0,fx=0,fy=0,farbe,poff;
FILE *Fn;
Fn=fopen(BMPFile,"rb"); //lese Farbpalette...
for(filepos=0;filepos<(BMPHeader.bfOffBits-64);filepos++)farbe=getc(Fn);
for(poff=0;poff<64;poff++,filepos++) Buffer[poff]=getc(Fn);
for(farbe=0;farbe<16;farbe++)
{ //codiere Farbpalette:
Hallo[farbe][2]=Buffer[4*farbe+0]/4;
Hallo[farbe][1]=Buffer[4*farbe+1]/4;
Hallo[farbe][0]=Buffer[4*farbe+2]/4;
}
setvgapalette256(&Hallo); //aktiviere Palette "Hallo"
BytesDiff=BMPInfo.biWidth&7;
BytesTMP=BytesDiff;
if(BytesTMP>0)BytesDiff=4-(BytesTMP>>1)-(BytesTMP&1);
for(fy=0;fy<BMPInfo.biHeight;fy++) //lese Bitmap...
{
BytesTMP=BytesDiff;
for(fx=0;fx<BMPInfo.biWidth;)
{
farbe=getc(Fn);
setzePunkt(fx++,((BMPInfo.biHeight-1)-fy),(farbe>>4)&15);
if(fx>=BMPInfo.biWidth)break;
setzePunkt(fx++,((BMPInfo.biHeight-1)-fy),farbe&15);
}
while(BytesTMP--)farbe=getc(Fn);
}
fclose(Fn);
}
void leseBMP8(char *BMPFile) //8Bit BMP-Datei
{
int filepos=0,poff=0,fx=0,fy=0,farbe;
FIL